﻿/*----------------------------------------------------------------
//   Copyright (C) 2012 YMSOFT All rights reserved 
//
//   CLR版本:   2.0.50727.3634
//   Namespace: ART.Common
//   FileName : JEmail
//   Description: 
// 
//   Created by YAOMING at 2012-10-28 14:16:52
//   http://www.loverer.com QQ:78867011
//
//   Modified: 
//   Modify description: 
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.IO;
using System.Net.Mail;
using System.Collections;

namespace ART.Common
{
    public class JEmail
    {
        public static void SendMail(string UserName, string PassWord, string SMTPServer, string Subject, string body, string FromEmail, string ToEmail, string[] FuJianList)
        {
            try
            {
                System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage();
                //发送端到接收端的邮箱地址
                myMail = new System.Net.Mail.MailMessage(FromEmail, ToEmail);
                myMail.Subject = Subject;
                myMail.Body = body;
                if (FuJianList != null)
                {
                    foreach (string str in FuJianList)
                    {
                        if (str != "")
                        {
                            string m_path = Utils.GetMapPath(str);
                            if (System.IO.File.Exists(m_path))
                            {
                                System.Net.Mail.Attachment myAttachment = new System.Net.Mail.Attachment(str, System.Net.Mime.MediaTypeNames.Application.Octet);
                                //MIME协议下的一个对象，用以设置附件的创建时间，修改时间以及读取时间
                                System.Net.Mime.ContentDisposition disposition = myAttachment.ContentDisposition;
                                disposition.CreationDate = System.IO.File.GetCreationTime(m_path);
                                disposition.ModificationDate = System.IO.File.GetLastWriteTime(m_path);
                                disposition.ReadDate = System.IO.File.GetLastAccessTime(m_path);

                                //用smtpclient对象里attachments属性，添加上面设置好的myattachment
                                myMail.Attachments.Add(myAttachment);
                            }
                        }
                    }
                }

                //建立发送对象client,验证邮件服务器，服务器端口，用户名，以及密码
                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(SMTPServer, 25);
                client.Credentials = new System.Net.NetworkCredential(UserName, PassWord);
                client.Send(myMail);

            }
            catch //(System.Exception ex)
            {

            }
        }

      
    }
}
